package com.gaga.metadata.common.enums;

import java.util.ArrayList;
import java.util.List;

public enum StatisticPeriodType {
    //TODO 这个format的值待讨论
    MINUTE("minute", "分", "yyyy-MM-dd HH24:MI", -10, "MINUTEKEY"),
    HOUR("hour", "时", "yyyy-MM-dd HH24", 0, "HOURKEY"),
    DAY("day", "日", "yyyy-MM-dd", 10, "DAYKEY"),
    WEEK("week", "周", "yyyy-MM-dd", 20, "WEEKKEY"),
    MONTH("month", "月", "yyyy-MM", 30, "MONTHKEY"),
    SEASON("season", "季节", "yyyy-MM-dd", 40, "SEASONKEY"),
    HALFYEAR("halfyear", "半年", "yyyy-MM-dd", 50, "HALFYEARKEY"),
    YEAR("year", "年", "yyyy", 60, "YEARKEY");

    private final String code;
    private final String info;
    private final String format;
    private final Integer order;
    private final String desc;

    StatisticPeriodType(String code, String info, String format, Integer order, String desc) {
        this.code = code;
        this.info = info;
        this.format = format;
        this.order = order;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public String getInfo() {
        return info;
    }

    public String getFormat() {
        return format;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getOrder() {
        return order;
    }

    public static List<StatisticPeriodType> getSupportedType(Integer order) {
        List<StatisticPeriodType> supportedTypeList = new ArrayList<>();
        for (StatisticPeriodType statisticPeriodType : values()) {
            if (statisticPeriodType.order.intValue() >= order.intValue()) {
                supportedTypeList.add(statisticPeriodType);
            }
        }
        return supportedTypeList;
    }

    public static StatisticPeriodType ofCode(String code) {
        for (StatisticPeriodType statisticPeriodType : values()) {
            if (statisticPeriodType.code.equalsIgnoreCase(code)) {
                return statisticPeriodType;
            }
        }
        return null;
    }

    public static StatisticPeriodType ofDesc(String desc) {
        for (StatisticPeriodType statisticPeriodType : values()) {
            if (statisticPeriodType.desc.equalsIgnoreCase(desc)) {
                return statisticPeriodType;
            }
        }
        return null;
    }
}
